package sim.tests.games.alone;

import java.util.Random;

import com.badlogic.gdx.math.Vector2;

import sim.Image;
import sim.Sprite;

public class Jar extends Sprite
{
	private boolean shake = false;
	private long shakeTimer;
	private boolean doShake = false;
	private float shakeAmount = 5;
	private float shakeSpeed = 200;
	private final float shakeTime = 400;

	public Jar(Vector2 pos)
	{
		this(pos.x, pos.y);

	}

	public Jar(float x, float y)
	{

		super(new Image("jar2.png"), x, y);
		bounds.set(x + 8, y + 8, 16, 16);

	}

	@Override
	public void update(float timeStep)
	{
		if (shake)
		{
			if (!doShake)
			{
				if (image.rotation < shakeAmount)
				{
					image.rotate(shakeSpeed * timeStep);
				} else
					doShake = true;
			} else
			{
				
				
				if(image.rotation > -shakeAmount)
					image.rotate(-shakeSpeed * timeStep);
				else
					doShake = false;

			}

			long currentTime = System.currentTimeMillis();
			
			if(currentTime - shakeTimer > shakeTime)
			{
				shake = false;
				image.rotation = 0;
			}
		}
	}

	public void shake()
	{
		shake = true;
		doShake = false;
		shakeTimer = System.currentTimeMillis();
	}

}
